package com.learning.rpc.rpc.cluster.loadbalance;

import com.learning.rpc.rpc.Invoker;
import com.learning.rpc.rpc.cluster.LoadBalance;

import java.net.URI;
import java.util.Map;
import java.util.Random;

/**
 * ClassName: RandomLoadBalance
 * Description: 随机负载均衡器
 * Date: 2022/5/10 23:01 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class RandomLoadBalance implements LoadBalance {

    @Override
    public Invoker select(Map<URI, Invoker> invokerMap) {
        int index = new Random().nextInt(invokerMap.values().size());
        return invokerMap.values().toArray(new Invoker[]{})[index];
    }
}
